# -*- coding: UTF-8 -*-

import random
from Planete import Planete
from Ressources import *
import math
from math import *
        
class Etoile:
    def __init__(self ,id ,x , y, z):
        self.idEtoile = id
        self.x = x
        self.y = y
        self.z = z
        self.listeNom = ["Metagross", "Dragonite", "Arceus", "Vanilite", "Giratina", "Buneary", "Teddiursa", "Rotom", "Klink", "Mew", "Entei", "Bidoof", "Sandile", "Blastoise", "Voltorb", "Uxie", "Mesprit", "Azelf", "Cryogonal", "Roggenrola", "Pikachu", "Darmanitan", "Empoleon", "Chimchar", "Geodude", "Feraligatr", "Arceus", "Torterra", "Regigigas", "Hydreigon", "Bulbasaur", "Ivysaur", "Druddigon", "Mew", "Jigglypuff", "Caterpie", "Rattata", "Cyndaquil", "Chikorita", "Charizard"]
        self.listePlanete=[]
        self.genererSysteme()
        self.isAffiche=False
        self.isChange=False
        self.isVisite=False
        
          
    def genererSysteme(self):
            if random.randint(0,7)>=1:
                nbr=random.randint(4,6)
                for i in range(nbr-1):
                    index = random.randint(0,39)
                    nomp = self.listeNom[index]+str(random.randint(0,1000))
                    self.genererPlanete(i, nomp)
        
                
    def genererPlanete(self, idPlanete, nomp):
        idPlanete = idPlanete 
        sysSolaire = self.idEtoile
        size = random.randint(1000000, 2000000)
        type = random.randint(1, 3)
        estHabitee = False     
        valide=True
        
        while(valide):
            valide=False
            #Donne les positions des planètes autour de l'etoile 
            posX = random.randint(-234,234)
            posY = random.randint(-234,234)
            posZ = random.randint(-234,234)
            #verifie que les positions ne sont pas égale a l'étoile(0)
            if ((posX >= 0 and posX < 90) or (posX <= 0 and posX > -90) ) or ((posY >= 0 and posY < 90) or (posY <= 0 and posY > -90) ):
                valide = True
            else:
                for i in self.listePlanete:
                 if(i.posX < posX+60 and i.posX > posX-60) and ((i.posY < posY+60 and i.posY > posY-60)):
                    valide = True
                    break
                        
        # Generer les ressources de la planete cible
        listeRessources = []
        qte = random.randint(5000,20000)
        ressource = Ressource("Minerais",qte,int(sqrt(size)),int(sqrt(size)))
        listeRessources.append(ressource)
        
        p=Planete(idPlanete,nomp,type,estHabitee,sysSolaire,size,self.x+posX,self.y+posY,self.z+posZ,"Aucun",listeRessources)
        self.listePlanete.append(p)
